package com.example.hao.flowercityfm.HFAdapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.hao.flowercityfm.R;
import com.example.hao.flowercityfm.pojo.Type3ListItem;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Type3Adapter extends RecyclerView.Adapter<Type3Adapter.ViewHolder> {


    private Context context;
    private View view;

    public Type3Adapter(Context context) {
        this.context = context;
    }

    private Type3ListItem item;

    public void setItem(Type3ListItem item) {
        this.item = item;
        notifyDataSetChanged();
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.fragment_home_type3_item, parent, false);


        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        Type3ListItem.DataBean dataBean = item.getData().get(position);
        String intro = dataBean.getIntro();
        holder.tvInformation.setText(intro);
        final String name = dataBean.getName();
        holder.tvName.setText(name);
        String pictureUrl = dataBean.getPictureUrl();
        Glide.with(context).load(pictureUrl).into(holder.ivBg);


        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context, name, Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public int getItemCount() {
//        return fragmentData == null ? 0 : fragmentData.getList().get(3)..size();
        return item == null ? 0 : item.getData().size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_bg)
        ImageView ivBg;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_information)
        TextView tvInformation;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
